package com.sqnu.test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//最基础版本 spring与web集成
//就是在servlet方法体中加载spring核心配置文件创建spring容器
//获取容器中存储的对象  并进行使用
@WebServlet("/a")
public class AServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        User bean = applicationContext.getBean(User.class);
        System.out.println(bean);
        applicationContext.close();
    }
}